{% extends "base.html" %} {% block title %}用户管理 - 运动健康管理系统{%
endblock %} {% block content %}
<div class="container py-5">
  <nav aria-label="breadcrumb">
    <ol class="breadcrumb">
      <li class="breadcrumb-item">
        <a href="{{ url_for('index') }}">首页</a>
      </li>
      <li class="breadcrumb-item active" aria-current="page">用户管理</li>
    </ol>
  </nav>

  <h1 class="mb-4"><i class="bi bi-people-fill"></i> 用户管理</h1>

  <!-- 搜索框 -->
  <div class="row mb-4">
    <div class="col-md-6">
      <form action="{{ url_for('admin_users') }}" method="GET" class="d-flex">
        <input
          type="text"
          name="keyword"
          class="form-control me-2"
          placeholder="搜索用户..."
          value="{{ keyword if keyword }}" />
        <button type="submit" class="btn btn-primary">搜索</button>
      </form>
    </div>
  </div>

  <div class="card shadow">
    <div class="card-body">
      <div class="table-responsive">
        <table class="table table-hover">
          <thead>
            <tr>
              <th>用户名</th>
              <th>电子邮箱</th>
              <th>手机号码</th>
              <th>注册时间</th>
              <th>操作</th>
            </tr>
          </thead>
          <tbody>
            {% for user in users %}
            <tr>
              <td>
                {{ user.username }} {% if user.is_admin %}
                <span class="badge bg-primary ms-1">管理员</span>
                {% endif %}
              </td>
              <td>{{ user.email }}</td>
              <td>{{ user.phone_number }}</td>
              <td>
                {{ user.register_time.strftime('%Y-%m-%d %H:%M') if
                user.register_time else '未知' }}
              </td>
              <td>
                <div class="d-flex">
                  <!-- 重置密码 -->
                  <form
                    action="{{ url_for('reset_user_password', user_id=user.id) }}"
                    method="POST"
                    class="me-2"
                    onsubmit="return confirm('确定要将该用户密码重置为111111吗？');">
                    <button type="submit" class="btn btn-sm btn-warning">
                      重置密码
                    </button>
                  </form>

                  <!-- 删除用户 -->
                  {% if not user.is_admin %}
                  <form
                    action="{{ url_for('delete_user', user_id=user.id) }}"
                    method="POST"
                    class="me-2"
                    onsubmit="return confirm('确定要删除该用户吗？此操作不可恢复！');">
                    <button type="submit" class="btn btn-sm btn-danger">
                      删除用户
                    </button>
                  </form>
                  {% endif %}
                </div>
              </td>
            </tr>
            {% else %}
            <tr>
              <td colspan="5" class="text-center">暂无用户数据</td>
            </tr>
            {% endfor %}
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>
{% endblock %}
